# -*- coding:utf-8 -*-
"""
HTTP/REST server with fastapi framework
"""
import os.path
import sys
import glob
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from app.api import include_router

def start_fastapi_server():
    app = FastAPI()
    app.add_middleware(GZipMiddleware, minimum_size=500)  # 添加 gzip 中间件
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    include_router(app)  # 添加路由
    for route in app.routes:
        print("router path    : {:15s} --> {}".format(str(route.methods), route.path))
    return app


if __name__ == '__main__':
    start_fastapi_server()
